from PyQt5.QtWidgets import QWidget,QHBoxLayout,QVBoxLayout,QPushButton, QLabel, QApplication
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
import os, time, sys
from uiDef import *

mapFile = "resource/map/test.png"

class MapWidget(QWidget):
    def __init__(self):
        super().__init__()
      
        #返回主界面
        self.homeBtn = QPushButton(self)
        self.homeBtn.setStyleSheet("QPushButton{border-image: url(resource/ic_home.png)}")
        self.homeBtn.setFixedSize(30, 30)
        self.headerLabel = QLabel(self)
        self.headerLabel.setText("地图")
        self.headerLabel.setStyleSheet("color:white")
        self.hBoxHeader = QHBoxLayout()
        self.hBoxHeader.addStretch(1)
        self.hBoxHeader.addWidget(self.headerLabel)
        self.hBoxHeader.addStretch(1)
        self.hBoxHeader.addWidget(self.homeBtn)
        
        #显示图片
        self.mapImg = QLabel(self)
        self.pixmap = QPixmap(mapFile)  # 按指定路径找到图片
        self.mapImg.setPixmap(self.pixmap)  # 在label上显示图片

        #整体布局
        self.vboxMain = QVBoxLayout()
        self.vboxMain.addLayout(self.hBoxHeader)
        self.vboxMain.addWidget(self.mapImg)
        self.setLayout(self.vboxMain)

        #信号与槽
        self.homeBtn.clicked.connect(self.returnHome)
        self.homeBtn.clicked.connect(self.close)
        
        self.initUI()

    # 初始化界面
    def initUI(self):
        self.resize(WIN_WIDTH, WIN_HEIGHT)
        self.setWindowTitle('地图')
        self.setStyleSheet("background-color:rgb(56,94,15)")
        self.show()
        
    # 返回主页
    def returnHome(self):
        print("return home")
        from homeUI import mainWindow
        self.homeWindow = mainWindow()
        self.homeWindow.show()

if __name__ =='__main__':
    import sys
    app = QApplication(sys.argv)
    my_widget = MapWidget()
    my_widget.show()
    sys.exit(app.exec())
